﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using RemoteTestRunner.BusinessLogic;
using RemoteTestRunner.BusinessLogic.ViewModels;

namespace RemoteTestRunner.FormsUI.Wpf
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        private void Start()
        {

            //System.Windows.Application
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.SetCompatibleTextRenderingDefault(false);

            //Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            Runner runnerInstance = new Runner();
            IoC.Container.RegisterInstance<Runner>(runnerInstance);

            //ProjectAdmin adminInstance = new ProjectAdmin();
            //IoC.Container.RegisterInstance<ProjectAdmin>(adminInstance);

            IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.ITestRunnerWpfView, Runner>();
            IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.IAdminView, ProjectAdmin>();

            IoC.Container.RegisterType<RunnerViewModel, RunnerViewModel>();
            IoC.Container.RegisterType<ProjectAdminViewModel, ProjectAdminViewModel>();

            //IoC.Container.RegisterType<ApplicationNavigationPresenter, ApplicationNavigationPresenter>();
            //IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.IApplicationNavigationView, Runner>();

            //IoC.Container.RegisterType<LongRunningPresenter, LongRunningPresenter>();
            //IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.ILongRunningView, LongRunning>();

            //IoC.Container.RegisterType<EditProjectsPresenter, EditProjectsPresenter>();
            //IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.IEditProjectsView, ProjectAdmin>();

            //IoC.Container.RegisterType<EditTestsPresenter, EditTestsPresenter>();
            //IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.IEditTestsView, TestAdmin>();

            //IoC.Container.RegisterType<OptionsPresenter, OptionsPresenter>();
            //IoC.Container.RegisterType<RemoteTestRunner.BusinessLogic.Views.IOptionsView, Options>();

            //PresenterBase navigationPresenter = IoC.Container.Resolve<ApplicationNavigationPresenter>();
            //navigationPresenter.Start();

            IViewModelBase mainViewModel = IoC.Container.Resolve<RunnerViewModel>();
            mainViewModel.Start();

            //var x = new Window1();
            //x.Show();

            //Application.Current.Run();

            //App.Current.Run();

        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show("Application exception:\n\n" + e.ExceptionObject.ToString());
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            MessageBox.Show("Application exception:\n\n" + e.Exception.ToString());
        }

        internal void Application_Startup(object sender, StartupEventArgs e)
        {
            Start();
        }

    }
}
